package 二三年8月;

import java.time.temporal.ValueRange;
import java.util.*;
import java.util.stream.Stream;

/**
 * 电话号码的字母组合
 *
 * 思路：每个电话号码下有三个字母，  所以需要进行二重组合，先组合电话号码，电话号码组合完之后，再组合对应字母
 *
 *  感觉要用递归 , dp[i+1] =  dp[i] + 1(循环当前位拼接)
 */
public class L_17 {

    public List<String> letterCombinations(String digits) {
        List<String> result =  new ArrayList<>();
        if(digits == null || digits.length() < 1){
            return result;
        }

        Map<Character, String> number = new HashMap<>();
        number.put('2',"abc");
        number.put('3',"def");
        number.put('4',"ghi");
        number.put('5',"jkl");
        number.put('6',"mno");
        number.put('7',"pqrs");
        number.put('8',"tuv");
        number.put('9',"wxyz");
        // 单个字母情况
        rescurStr(digits,0,result,new StringBuffer(),number);
//        rescurStr1(digits,0,result,new StringBuffer());
        return  result;
    }


    private void rescurStr(String s, int i,List<String> result,StringBuffer combine,Map<Character, String> number ){
        if(i == s.length()){
            result.add(combine.toString());
            return;
        }
        String valueStr = number.get(s.charAt(i));
        int len = valueStr.length();
        for (int j = 0; j < len ; j++) {
            combine.append(valueStr.charAt(j));
            rescurStr(s,i+1,result,combine,number);
            // 循环过后清空当前位
            combine.deleteCharAt(i);
        }
    }



}
